home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / archiver / arc.zoo / arcdos.c < prev    next >
C/C++ Source or Header  |  1991-08-13  |  5KB  |  220 lines

  1. /*
  2.  * $Header: arcdos.c,v 1.8 88/08/01 15:07:15 hyc Exp $
  3.  */
  4.  
  5. /*
  6.  * ARC - Archive utility - ARCDOS
  7.  * 
  8.  * Version 1.44, created on 07/25/86 at 14:17:38
  9.  * 
  10.  * (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  11.  * 
  12.  * By:  Thom Henderson
  13.  * 
  14.  * Description: This file contains certain DOS level routines that assist in
  15.  * doing fancy things with an archive, primarily reading and setting the date
  16.  * and time last modified.
  17.  * 
  18.  * These are, by nature, system dependant functions.  But they are also, by
  19.  * nature, very expendable.
  20.  * 
  21.  * Language: Computer Innovations Optimizing C86
  22.  */
  23. #include <stdio.h>
  24. #include "arc.h"
  25.  
  26. #if    MSDOS
  27. #include "fileio2.h"        /* needed for filehand */
  28. #endif
  29.  
  30. #if    UNIX
  31. #include <sys/types.h>
  32. #include <sys/stat.h>
  33. #include <time.h>
  34.  
  35. #ifndef hpux
  36. struct timeval {    /* man page said <sys/types.h>, but it */
  37.     long tv_sec;    /* really seems to be in <sys/time.h>, */
  38.     long tv_usec;    /* but why bother... */
  39. };
  40. #endif
  41. #endif
  42.  
  43. #if    GEMDOS
  44. #include <osbind.h>
  45. #endif
  46.  
  47. #ifndef __STDC__
  48. char    *strcpy(), *strcat(), *malloc();
  49. #endif
  50.  
  51. void
  52. getstamp(f, date, time)        /* get a file's date/time stamp */
  53. #if    !MTS
  54.     FILE           *f;    /* file to get stamp from */
  55. #else
  56.     char           *f;    /* filename "" "" */
  57. #endif
  58.     unsigned short   *date, *time;    /* storage for the stamp */
  59. {
  60. #if    MSDOS
  61.     struct {
  62.         int             ax, bx, cx, dx, si, di, ds, es;
  63.     }               reg;
  64.  
  65.     reg.ax = 0x5700;    /* get date/time */
  66.     reg.bx = filehand(f);    /* file handle */
  67.     if (sysint21(®, ®) & 1)    /* DOS call */
  68.         printf("Get timestamp fail (%d)\n", reg.ax);
  69.  
  70.     *date = reg.dx;        /* save date/time */
  71.     *time = reg.cx;
  72. #endif
  73. #if    GEMDOS
  74.     int    fd, ret[2];
  75.  
  76.     fd = fileno(f);
  77.     Fdatime(ret, fd, 0);
  78.     *date = ret[1];
  79.     *time = ret[0];
  80. #endif
  81. #if    UNIX
  82.     struct stat    buf;
  83.     struct tm    *localtime(), *t;
  84.  
  85.     fstat(fileno(f), &buf);
  86.     t=localtime(&(buf.st_mtime));
  87.     *date = (unsigned short) (((t->tm_year - 80) << 9) +
  88.                 ((t->tm_mon + 1) << 5) + t->tm_mday);
  89.     *time = (unsigned short) ((t->tm_hour << 11) +
  90.                 (t->tm_min << 5) + t->tm_sec / 2);
  91. #endif
  92. #if    MTS
  93.     fortran         timein(),
  94. #if    USEGFINFO
  95.                     gfinfo();
  96. #else
  97.                     fileinfo();
  98. #endif
  99.     int             stclk[2];
  100.     char            name[24];
  101.     struct bigtime {
  102.         int             greg;
  103.         int             year;
  104.         int             mon;
  105.         int             day;
  106.         int             hour;
  107.         int             min;
  108.         int             sec;
  109.         int             usec;
  110.         int             week;
  111.         int             toff;
  112.         int             tzn1;
  113.         int             tzn2;
  114.     }               tvec;
  115. #if    USEGFINFO
  116.     static int      gfflag = 0x0009, gfdummy[2] = {
  117.                                0, 0
  118.     };
  119.     int             gfcinfo[18];
  120. #else
  121.     static int      cattype = 2;
  122. #endif
  123.  
  124.     strcpy(name, f);
  125.     strcat(name, " ");
  126. #if    USEGFINFO
  127.     gfcinfo[0] = 18;
  128.     gfinfo(name, name, &gfflag, gfcinfo, gfdummy, gfdummy);
  129.     timein("*IBM MICROSECONDS*", &gfcinfo[16], &tvec);
  130. #else
  131.     fileinfo(name, &cattype, "CILCCT  ", stclk);
  132.     timein("*IBM MICROSECONDS*", stclk, &tvec);
  133. #endif
  134.  
  135.     *date = (unsigned short) (((tvec.year - 1980) << 9) + ((tvec.mon) << 5) + tvec.day);
  136.     *time = (unsigned short) ((tvec.hour << 11) + (tvec.min << 5) + tvec.sec / 2);
  137. #endif
  138. }
  139.  
  140. void
  141. setstamp(f, date, time)        /* set a file's date/time stamp */
  142.     char           *f;    /* filename to stamp */
  143.     unsigned short    date, time;    /* desired date, time */
  144. {
  145. #if    MSDOS
  146.     FILE    *ff;
  147.     struct {
  148.         int             ax, bx, cx, dx, si, di, ds, es;
  149.     }               reg;
  150.  
  151.     ff = fopen(f, "w+");    /* How else can I get a handle? */
  152.  
  153.     reg.ax = 0x5701;    /* set date/time */
  154.     reg.bx = filehand(f);    /* file handle */
  155.     reg.cx = time;        /* desired time */
  156.     reg.dx = date;        /* desired date */
  157.     if (sysint21(®, ®) & 1)    /* DOS call */
  158.         printf("Set timestamp fail (%d)\n", reg.ax);
  159.     fclose(ff);
  160. #endif
  161. #if    GEMDOS
  162.     int    fd, set[2];
  163.  
  164.     fd = Fopen(f, 0);
  165.     set[0] = time;
  166.     set[1] = date;
  167.     Fdatime(set, fd, 1);
  168.     Fclose(fd);
  169. #endif
  170. #if    UNIX
  171.     struct tm    tm;
  172.     struct timeval  tvp[2];
  173.     int    utimes();
  174. #ifdef MINIX
  175.     long    mktime();
  176. #else
  177.     long    tmclock();
  178. #endif
  179.  
  180.     tm.tm_sec = (time & 31) * 2;
  181.     tm.tm_min = (time >> 5) & 63;
  182.     tm.tm_hour = (time >> 11);
  183.     tm.tm_mday = date & 31;
  184.     tm.tm_mon = ((date >> 5) & 15) - 1;
  185.     tm.tm_year = (date >> 9) + 80;
  186. #ifdef MINIX
  187.     tvp[0].tv_sec = mktime(&tm);
  188. #else
  189.     tvp[0].tv_sec = tmclock(&tm);
  190. #endif
  191.     tvp[1].tv_sec = tvp[0].tv_sec;
  192.     tvp[0].tv_usec = tvp[1].tv_usec = 0L;
  193.     utimes(f, tvp); 
  194.  
  195. #endif
  196. }
  197.  
  198. #if    MSDOS
  199. int
  200. filehand(stream)        /* find handle on a file */
  201.     struct bufstr  *stream;    /* file to grab onto */
  202. {
  203.     return stream->bufhand;    /* return DOS 2.0 file handle */
  204. }
  205. #endif
  206.  
  207. #if    UNIX
  208. int
  209. izadir(filename)        /* Is filename a directory? */
  210.     char           *filename;
  211. {
  212.     struct stat     buf;
  213.  
  214.     if (stat(filename, &buf) != 0)
  215.         return (0);    /* Ignore if stat fails since */
  216.     else
  217.         return (buf.st_mode & S_IFDIR);    /* bad files trapped later */
  218. }
  219. #endif
  220.